package xkp.lesson1;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Arrays;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import xkp.lesson.utils.ArraysUtils;

public class TestJunit {
	//测试二分查找与普通查找的性能
	//首先要有数组
	//生成数组
	//使用随机数生成数组
	
	//两个测试要使用同一个数组
	private static int[] arr;
	private int[] newArr;
	
	@BeforeClass
	public static void beforeClass() {
		int count = 100*100*10;
		arr = new int[count];
		System.out.println("beforeClass()");
		//对数组进行初始化,可以使用随机数生成100*100*100个数值
		for(int i = 0; i < count; i++) {
			int num = (int) (Math.random()*count);
			arr[i] = num;
		}
	}
	
	@Before
	public void before() {
		newArr = Arrays.copyOf(arr, arr.length);
		System.out.println("before()");
	}
	
	@Test
	public void test1() {
		//测试快速
		ArraysUtils.quickSort(newArr, 0, newArr.length-1);
		System.out.println("test1()");
	}
	

	@Test
	public void test2() {
		//测试冒泡
		ArraysUtils.maopao(newArr);
		System.out.println("test2()");
	}
	
	@Test
	public void test3() {
		//int n = 10/0;
		//测试失败表示语法层面没有问题，功能逻辑有问题
		int n = 10/0;
		//断言判断
		assertEquals(5,sum(2,3));
		
	}
	
	
	@After
	public void after() {
		System.out.println("after()");
	}
	
	
	@AfterClass
	public static void afterClass() {
		System.out.println("afterClass()");
	}
	
	public int sum(int num1,int num2) {
		return num1+num2-1;
	}
}
